package com.mathlearning.auth.repository;

import com.mathlearning.auth.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
    Optional<User> findByPhone(String phone);
    Optional<User> findByOpenid(String openid);
    boolean existsByPhone(String phone);
    
    /**
     * 增加用户学习时长
     */
    @Modifying
    @Query("UPDATE User u SET u.totalStudyMinutes = u.totalStudyMinutes + :minutes WHERE u.id = :userId")
    void incrementStudyMinutes(@Param("userId") Long userId, @Param("minutes") Integer minutes);
}



